﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Meetings
{
    public partial class AgendaItemDialog : Form
    {
        public AgendaItem Info
        {
            get
            {
                AgendaItem i = new AgendaItem();

                i.Abstain = (int)numericAbstained.Value;
                i.AddedAtMeeting = checkAdded.Checked;
                i.Carried = checkCarried.Checked;
                i.Deferred = checkDeferred.Checked;
                i.InFavor = (int)numericFavor.Value;
                i.Motion = textMotion.Text;
                i.MovedBy = textMoved.Text;
                i.Notes = textDiscussion.Text;
                i.Opposed = (int)numericOpposed.Value;
                i.Seconder = textSecond.Text;
                i.Title = textTitle.Text;

                return i;
            }

            set
            {
                checkAdded.Checked = value.AddedAtMeeting;
                checkCarried.Checked = value.Carried;
                checkDeferred.Checked = value.Deferred;
                numericAbstained.Value = value.Abstain;
                numericFavor.Value = value.InFavor;
                numericOpposed.Value = value.Opposed;
                textDiscussion.Text = value.Notes;
                textMotion.Text = value.Motion;
                textMoved.Text = value.MovedBy;
                textSecond.Text = value.Seconder;
                textTitle.Text = value.Title;
            }
        }

        public AgendaItemDialog()
        {
            InitializeComponent();
        }

        private void toolCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void toolOK_Click(object sender, EventArgs e)
        {
            bool ok = true;

            if (textTitle.Text == "")
            {
                ok = false;
                MessageBox.Show("This agenda item must have a description");
            }

            if (textMotion.Text != "")
            {
                if (textMoved.Text == "" || textSecond.Text == "" || (numericAbstained.Value == 0 && numericFavor.Value == 0 && numericOpposed.Value == 0))
                {
                    ok = false;
                    MessageBox.Show("You must enter the details of the motion");
                }
            }

            if (ok)
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
